From d510d0c0c7dd99340bbdd97b9780d928e87b6d9d Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Sat, 25 May 2013 19:19:55 -0400 Subject: [PATCH] Language::convertPlural: check if matching form exists It is possible that only explicit plural forms are specified, and therefore, it is possible that none match. However, handling of explicit forms came after the count( $forms ) check, so input such as {{PLURAL:|1=}} would trigger a "PHP Notice: Undefined offset: -1". Change-Id: I8494de8ceb9e0cfff7203c69c21f02b3731275af Follows-Up: I50eb0c6d1c02ca936848d310de625ed1fe43d91a --- RELEASE-NOTES-1.22 | 1 + languages/Language.php | 8 ++++---- tests/phpunit/languages/LanguageTest.php | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 361ab25e93..b6a8e2931a 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -106,6 +106,7 @@ production. strings will now start with digits 0 and 8-f as often as they should. * (bug 45371) Removed Parser_LinkHooks and CoreLinkFunctions classes. * (bug 41545) Allow , , and to be nested like allowed in html. +* PLURAL magic word no longer causes a PHP notice when no matching form exists. === API changes in 1.22 === * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the diff --git a/languages/Language.php b/languages/Language.php index c73ccd1eab..9301e5476f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3597,10 +3597,6 @@ class Language { * @return string Correct form of plural for $count in this language */ function convertPlural( $count, $forms ) { - if ( !count( $forms ) ) { - return ''; - } - // Handle explicit n=pluralform cases foreach ( $forms as $index => $form ) { if ( preg_match( '/\d+=/i', $form ) ) { @@ -3611,7 +3607,11 @@ class Language { unset( $forms[$index] ); } } + $forms = array_values( $forms ); + if ( !count( $forms ) ) { + return ''; + } $pluralForm = $this->getPluralRuleIndexNumber( $count ); $pluralForm = min( $pluralForm, count( $forms ) - 1 ); diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 54f7753d30..d687dbbd93 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1384,6 +1384,9 @@ class LanguageTest extends LanguageClassesTestCase { array( 'other', 2, array( 'kissa=kala', '1=2=3', 'other', ) ), + array( '', 2, array( + '0=explicit zero', '1=explicit one', + ) ), ); } -- 2.20.1